package com.example.win.android_banduyujia.peopleactivity.activity.activity.openactivity.DataActivity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.example.win.android_banduyujia.R;
import com.example.win.android_banduyujia.lib.util.StrUtils;
import com.example.win.android_banduyujia.peopleactivity.ui.activity.BaseTitleBarActivity;

/**
 * Created by Win on 2015/8/18.
 */
public class UpdateNameActivity extends BaseTitleBarActivity {
    public static final String  USER_NICKNAME = "UpdateGenderActivity.USER_NICKNAME";

    private EditText    mEditTextNickName;
    private ImageView   mImageViewDelete;
    private String      mNickName = " ";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_update_nick_name);

        InitTitles();
        InitViews();
        InitDatas();
    }

    private void InitTitles() {
        setTitle(R.string.layout_data_page_edit_view_name);
        showLeftBackButton();
        setRightTextViewListener(R.string.layout_data_save_button, mSaveListener);
    }

    private void InitDatas() {
        mNickName = getIntent().getStringExtra(USER_NICKNAME);
        mEditTextNickName.setText(mNickName);
    }

    private void InitViews() {
        mEditTextNickName = (EditText)findViewById(R.id.update_name_edit_text);
        mImageViewDelete = (ImageView)findViewById(R.id.update_name_image_icon);
        mImageViewDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mEditTextNickName.setText(" ");
            }
        });
        mEditTextNickName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                         }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                          }

            @Override
            public void afterTextChanged(Editable s) {
                mNickName = s.toString();
                if(StrUtils.isEmpty(mNickName)){
                    mImageViewDelete.setVisibility(View.GONE);
                }else{
                    mImageViewDelete.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    private View.OnClickListener mSaveListener = new View.OnClickListener(){

        @Override
        public void onClick(View v) {
            if(StrUtils.isEmpty(mNickName)){
                showToast(R.string.personnal_info_activity_nick_name_hint);
                return;
            }
            saveNickName();
        }
    };

    private void saveNickName() {

    }
}
